package com.jemmyee.pizza.web.utils;

import java.io.IOException;
import org.smslib.GatewayException;
import org.smslib.OutboundMessage;
import org.smslib.TimeoutException;
import org.smslib.Message.MessageEncodings;
import com.jemmyee.core.web.listener.ApplicationListener;

/**
 * @author qiuchao 2011-2-28
 */
public class SendMessageUtils extends ApplicationListener {
	public static String send(String phoneNO, String message) throws Exception {
		try {
			OutboundMessage msg;
			System.out.println("send message to : " + phoneNO);
			System.out.println("message content : " + message);
			msg = new OutboundMessage(phoneNO, message);
			msg.setEncoding(MessageEncodings.ENCUCS2);// 这句话是发中文短信必须的
			srv.sendMessage(msg);
		} catch (TimeoutException e) {
			e.printStackTrace();
			return new String("发送超时".getBytes(), "GBK");
		} catch (GatewayException e) {
			e.printStackTrace();
			return new String("初始化网关失败".getBytes(), "GBK");
		} catch (IOException e) {
			e.printStackTrace();
			return new String("IO异常".getBytes(), "GBK");
		} catch (InterruptedException e) {
			e.printStackTrace();
			return new String("发送程序异常中止".getBytes(), "GBK");
		}

		return new String("发送成功".getBytes(), "GBK");
	}

}
